package com.sensoro.study.stream;

import java.util.stream.Stream;

public class StreamStudy {

    public static void main(String[] args) {
        testTakeWhile();
        System.out.println("-----------------------");
        testDropWhile();
        System.out.println("-----------------------");
        testOfNullAble();
    }

    /**
     * takeWhile:返回stream的子集
     * 一直取直到不满足条件
     */
    private static void testTakeWhile() {
        Stream.of("a", "c", "b", "", "d", "e", "f").takeWhile(item -> !item.isEmpty()).forEach(System.out::println);
    }


    /**
     * dropWhile和takeWhile相反
     * 从满足断言的结果开始返回Stream子集
     */
    private static void testDropWhile() {
        Stream.of("a", "c", "b", "", "d", "e", "f").dropWhile(item -> !item.isEmpty()).forEach(System.out::println);
    }

    private static void testOfNullAble() {
        System.out.println(Stream.ofNullable(null).count());
    }
}
